﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.Cecil;

namespace devtm.Aop.Extensions
{
    
    public static class ModuleDefinitionExt
    {

        public static List<TypeDefinition> GetAllTypeDefinitions(this ModuleDefinition moduleDefinition)
        {
            var definitions = new List<TypeDefinition>();
            moduleDefinition.Types.Skip(1).GetTypes(definitions);
            return definitions;
        }



        public static TypeReference AsType(this ModuleDefinition module, string type)
        {

            foreach (TypeDefinition item in module.Types)            
                if (item.FullName == type)
                    return item;            

            return null;

        }


        public static IEnumerable<TypeReference> Import(this ModuleDefinition module, IEnumerable<Type> types)
        {

            foreach (Type type in types)            
                yield return module.Import(type);
            
        }

    }
}
